//路由配置信息

//引入路由文件

import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
import MyOrder from '@/pages/Center/MyOrder'
import GroupOrder from '@/pages/Center/GroupOrder'
import Pay from '@/pages/Pay'

export default [
    // 项目开始，访问/ 立马重定向到首页
    {
        path:'/',
        redirect:'/home',
    },
    {
        path:'/home',
        component:() => import('@/pages/Home'),  //路由懒加载
        meta:{show:true}
    },
    {
        name:'search',
        path:'/search/:keyword?',
        component:Search,
        props:true,
        meta:{show:true}
    },
    {
        path:'/login',
        component:Login,
        meta:{show:false}
    },
    {
        path:'/register',
        component:Register,
        meta:{show:false}
    },
    {
        path:'/detail/:skuId',
        component:Detail,
        meta:{show:true}
    },
    {
        name:"addCartSuccess",
        path:'/addCartSuccess',
        component:AddCartSuccess,
        meta:{show:true},
        beforeEnter: (to, from, next) => {
            if(from.path=="/pay") next();
            else next(false) //url重置到from的path
        }
    },
    {
        name:"shopCart",
        path:'/shopCart',
        component:ShopCart,
        meta:{show:true}
    },
    {
        name:"trade",
        path:'/trade',
        component:Trade,
        meta:{show:true},
        beforeEnter: (to, from, next) => {
            if(from.path=="/shopcart") next();
            else next(false)  //url重置到from的path
        }
    },
    {
        name:"pay",
        path:'/pay',
        component:Pay,
        meta:{show:true},
        beforeEnter: (to, from, next) => {
            if(from.path=="/trade") next();
            else next(false) //url重置到from的path
        }
    },
    {
        name:"center",
        path:'/center',
        component:Center,
        meta:{show:true},
        children:[
            {
                name:"myorder",
                path:'/center/myorder',
                component:MyOrder,
            },
            {
                name:"grouporder",
                path:'/center/grouporder',
                component:GroupOrder,
            },
            {
                path:'/center',
                redirect:'/center/myorder'
            }
        ]
    },
    {
        name:"paySuccess",
        path:'/paySuccess',
        component:PaySuccess,
        meta:{show:true}
    },
]